drive space

Hello,

Is there a better approach to achieve this goal? Thank you.
 

/*
{bool|string} sendEMailNotification(string fromDescription,
string targetAddress, string subject,
string message)
*/
 
Regexp freespace = regexp ".*Dir.* (.*) .*bytes.free" 
string result = null
win32SystemWait_("cmd.exe /C dir E:\\", result, -1)
 
string    StripCommas(string in_String)
{
        int y = 0
        Buffer  bufStrip = create()  // Local to following function
        bufStrip = ""
        
        for (y = 0; y < length(in_String); y++) {
           if (in_String[y] == ',') continue
           bufStrip += in_String[y]
        }
        string results = stringOf(bufStrip)
        delete bufStrip
        
        return(results)
}
 
if (freespace result)
{
        //1 gigabytes = bytes / 1073741824
        real GB = realOf(StripCommas(result[match 1])) / realOf 1073741824
        if(GB < 3.0) {
                const string subject       = "Need to Request addition drive space for ????"
                const string message       = "Drive [E:\\] has {" GB "} GB free, please request additional drive space from IT. Thank you!"
                const string targetAddress = "james.ellis@ABC.com"
                sendEMailNotification(null, targetAddress, subject, message)
        }
}
 
delete freespace

 


-Jim

 


SystemAdmin - Mon Mar 04 14:59:26 EST 2013

Re: drive space
Mathias Mamsch - Mon Mar 04 16:36:02 EST 2013

You can use the WMI. See here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394592%28v=vs.85%29.aspx

Maybe this helps, regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: drive space
SystemAdmin - Tue Mar 05 04:07:32 EST 2013

Normally I use the filesystemobject for this stuff - http://msdn.microsoft.com/en-us/library/aa242706(v=vs.60).aspx

But I cannot say "better". It is something different.

Re: drive space
SystemAdmin - Tue Mar 05 10:06:34 EST 2013

Mathias Mamsch - Mon Mar 04 16:36:02 EST 2013
You can use the WMI. See here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394592%28v=vs.85%29.aspx

Maybe this helps, regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

How would you go about converting the following vbs to dxl this was my first attempt I would like to get the AvailableSpace of a drive. Thank you.
 

///----------------------------------------------------------------------
//                        vbs
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDrive = objFSO.GetDrive("E:")
Wscript.Echo "Available space: " & ConvertSize(objDrive.AvailableSpace)
///----------------------------------------------------------------------
//                        DXL
string result = null
OleAutoObj FileSystemObject = oleCreateAutoObject("Scripting.FileSystemObject")
OleAutoObj myGetDrive
 
OleAutoArgs args = create() 
put(args, "E:")
result = oleMethod (FileSystemObject, "GetDrive", args, myGetDrive)
print result

 


-Jim

 

Re: drive space
Tony_Goodman - Tue Mar 05 10:52:32 EST 2013

SystemAdmin - Tue Mar 05 10:06:34 EST 2013

How would you go about converting the following vbs to dxl this was my first attempt I would like to get the AvailableSpace of a drive. Thank you.
 

///----------------------------------------------------------------------
//                        vbs
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDrive = objFSO.GetDrive("E:")
Wscript.Echo "Available space: " & ConvertSize(objDrive.AvailableSpace)
///----------------------------------------------------------------------
//                        DXL
string result = null
OleAutoObj FileSystemObject = oleCreateAutoObject("Scripting.FileSystemObject")
OleAutoObj myGetDrive
 
OleAutoArgs args = create() 
put(args, "E:")
result = oleMethod (FileSystemObject, "GetDrive", args, myGetDrive)
print result

 


-Jim

 

I don't this approach will work because the Drive.FreeSpace property will return an integer that is too big for DXL to cope with.
Try the following anyway.

OleAutoObj  fsObj     = null
    OleAutoObj  driveObj     = null
        OleAutoArgs args          = create
 
        string res = ""
        int i = 0
        
        fsObj = oleCreateAutoObject("Scripting.FileSystemObject")
        
        if (null fsObj)
        {
                print("Failed to create fs object")
        }
        
        put(args, "c:")   
        res = oleMethod(fsObj, "GetDrive", args, driveObj)
        
        if (null driveObj)
        {
                print("Failed to create drive object")
        }
        
        oleGet(driveObj, "FreeSpace", i)
        
        print i ""

 


Tony Goodman, www.smartdxl.com